
local locplayer = ac.player.self

--抽卡面板
local ui = class.select_data.create(5)
ui:set_level(99)
ui.sync_name = '玩家-学习技能'


local mt = ac.skill['学习技能']
mt.art = [[ReplaceableTextures\CommandButtons\BTNSkillz.blp]]

function mt:on_cast_shot()
    local unit = self.owner
    local player = unit.owner
    local hero = player.hero
    local list = {}
    for _,temp in ipairs(get_hero_skill_list()) do
        if not hero:find_skill(temp.name,'英雄') then
            table.insert(list,temp)
        end
    end
    local data = table.random_table(list,3)
    player:set_data('学习技能表',data)
    if player:is_self() then
        ui:set_data(data)
    end
end




ac.sync:event '玩家-学习技能'(function(_,player,index)
    local data = player:get_data('学习技能表')
    local hero = player.hero
    local temp = data and data[index]
    if temp then
        local dialog = ac.dialog('替换技能')

        for a=1,6 do
            local skill = hero:find_skill(a,'英雄')
            if not skill then
                hero:add_skill(temp.name,'英雄',a)
                return
            end
            dialog:add_button({
                skill = skill,
                key = skill.name,
                index = a,
            })
        end

        dialog:add_button({
            key = '不想换了',
        })
        
        function dialog:on_click(button, player)
            local skill = button.skill
            if skill then
                skill:remove()
                hero:add_skill(temp.name,'英雄',button.index)
            end
            self:hide()
            
        end

        if player:is_self() then
            dialog:show() 
        end

    end
end)